#import "SEGBanalcesManager.h"

#if __has_include(<Commom/SEGModel.h>)
#import <Commom/SEGModel.h>
#else
#import "SEGModel.h"
#endif
#if __has_include(<Commom/SEGHTTPBusinessManager.h>)
#import <Commom/SEGHTTPBusinessManager.h>
#else
#import "SEGHTTPBusinessManager.h"
#endif

static id _BanalcesManager;
static dispatch_once_t onceToken;

@implementation SEGBanalcesManager
#pragma mark - SINGLE----BEGIN----
+(instancetype)sharedManager{
    dispatch_once(&onceToken, ^{
        _BanalcesManager = [[self alloc] init];
    });
    return _BanalcesManager;
}

+(void)destroyResource{
    onceToken = 0;
    _BanalcesManager = nil;
}

#pragma mark - SINGLE----END----

#pragma mark - HTTP----BEGIN----
-(void)requestBanalcesWithParameters:(NSDictionary*)parameters finished:(void(^)(BOOL isSuccessed,id result,NSString* codeType,NSString* errorMessage))finished{
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/uhomecp-sso/v1/balalce/getBanalces",nil];
    [SEGHTTPBusinessManager seg_requestWithMethod:POST URLString:urlString parameters:parameters completed:^(BOOL isSuccessed, id result, NSString *codeType, NSError *error) {
        if (!isSuccessed) {
            finished(isSuccessed,nil,codeType,error.localizedDescription);
            return;
        }
        
        NSArray* data = [result valueForKey:@"data"];
        if (![data isKindOfClass:[NSArray class]]) {
           finished(NO,result,codeType,error.localizedDescription);
             return;
        }
        
        NSMutableArray<SEGBanalcesModel*>* arrM = [NSMutableArray arrayWithCapacity:data.count];
        
        for (NSDictionary* dic in data) {
            SEGBanalcesModel *tmp = [SEGBanalcesModel yy_modelWithDictionary:dic];
            [arrM addObject:tmp];
        }
        
        self.Banalces = [NSArray arrayWithArray:arrM];
        finished(isSuccessed,result,codeType,error.localizedDescription);
        return;
    }];
}
#pragma mark - HTTP----END----

#pragma mark - GETTER----BEGIN----
-(NSArray<SEGBanalcesModel*> *)Banalces{
    if (!_Banalces) {
        _Banalces = [[NSArray alloc]init];
    }
    return _Banalces;
}
#pragma mark - GETTER----END----
@end

